/**
 * 
 * @author Travis C lynch <travisclynch@student.midlandstech.edu>
 * @version May 07 2012
 * <p>
 * <b>Instructions:</b><br>
 * Write a definition for a generic method named signSort and two utility methods named onlyLess and onlyMore, 
 * so they work with the following utility method and main method to generate an array of Integers between -100 and 100, 
 * then print it, then rearrange answer so that all of the Integers less than 0 are before all of the Integers greater than or equal to 0, \
 * but otherwise in the original order, and print answer again.
 * <p>
 * The public static void signSort method is a Generic method, 
 * with a type that must be Comparable or inherit from a Comparable class. It has four parameters.
 * <ul>
 * <li>An array of the Generic type elements representing the original array 
 * <li>A Generic type parameter representing the zero value. 
 * <li>An array of the Generic type elements representing the array of values less than zero. 
 * <li>An array of the Generic type elements representing the array of values greater than or equal to zero. 
 * <li>signSort calls onlyLess and onlyMore 
 * </ul>
 * The public static onlyLess method returns an int and is a Generic method, 
 * with a type that must be Comparable or inherit from a Comparable class. It has three parameters.
 * <ul>
 * <li>An array of the Generic type elements representing the original array 
 * <li>A Generic type parameter representing the zero value. 
 * <li>An array of the Generic type elements representing the array of values less than zero. 
 * <li>It returns the actual number of elements in the array of values less than zero. 
 * </ul>
 * <p>
 * <b>Description:</b><br>
 * A class that uses generic data types
 * 
 */
import java.util.*;

public class Hw4 {
	/**
	 * loads the array with random numbers
	 * 
	 * @returns an array of 50 Integers between -100 and 100
	 */
	private static Integer[] getRandomList() {
		Integer[] list = new Integer[50];
		for (int i = 0; i < 50; i++)
			list[i] = new Integer((int) (Math.random() * 201) - 100);
		return list;
	}

	public static <C extends Comparable <C>> void signSort(C[] comparables, C compareTo, C[] less, C[] more) {
		int sizeL = onlyLess(comparables, compareTo, less);
		int sizeM = onlyMore(comparables, compareTo, more);
		int Counter = 0;

		for (int i = 0; i<sizeL; i++) {
			comparables[Counter] = less[i];
			Counter++;
		}

		for (int i = 0; i< sizeM; i++) {
			comparables[Counter] = more[i];
			Counter++;
		}
	}

	public static <C extends Comparable<C>> int onlyLess(C[] comparables, C compareTo, C[] less) {
		int size = 0;
		for (C comparable : comparables) {
			if (comparable.compareTo(compareTo) == -1) {
				less[size] = comparable;
				size++;
			}
		}
		return size;
	}
	
	public static <C extends Comparable<C>> int onlyMore(C[] comparables, C compareTo, C[] less) {
		int size = 0;
		for (C comparable : comparables) {
			if (comparable.compareTo(compareTo) >= 0) {
				less[size] = comparable;
				size++;
			}
		}
		return size;
	}

	public static void main(String[] args) {
		Integer[] answer = getRandomList();
		Integer[] less = new Integer[answer.length];
		Integer[] more = new Integer[answer.length];
		System.out.println(Arrays.toString(answer) + "\n\n");
		signSort(answer, new Integer(0), less, more);
		System.out.println(Arrays.toString(answer));
	}

}
